package Controller;

/**
 * Controla os eventos quando o jogo esta no menu principal.
 * 
 * @author Edjane Catolle, Igor Henrique, Luiz Augusto, Vladmir Chicarolli
 * @version 1.0.0
 * @since 05/31/2011
 */

import View.MenuView;

public class MenuController extends BaseController
{
	
	private int menuState = 0;
	
	//Quantidade de itens do menu. Vai de 0 ~ 3
	private static final int ITENS_QTT 	=	3;
	
	//Os estados do menu
	private static final int NEW_GAME 	= 	0;
	private static final int HELP 		= 	1;
	private static final int CREDITS 	= 	2;
	private static final int EXIT 		= 	3;	
	private boolean select = false;

	public MenuController()
	{			
		view = new MenuView();
		controller = this;
	}
	
	@Override
	protected void ControllerHandler() 
	{
		if(select)
		{
			view.ClearBuffer();
			switch (menuState)
			{
				case NEW_GAME:
					new GameController();
				break;
				
				case HELP:					
					new HelpController();
				break;
				
				case CREDITS:					
					new CreditsController();
				break;
				
				case EXIT:
					System.exit(0);
				break;
			}
		}
		
		if(view instanceof MenuView)
		{
			((MenuView)view).setMenuState(menuState);
		}
	}

	@Override
	public void HandleKeyboard()
	{
		// 10 = Enter key
		if(GameControlsManager().GetKey() == 10)
		{
			select = true;
		}
		
		//38 = UP arrow key
		if(GameControlsManager().GetKey() == 38)
		{
			if(menuState > 0)
			{
				menuState --;
			}
			else
			{
				menuState = ITENS_QTT;
			}
		}
		
		//40 = DOWN arrow key
		if(GameControlsManager().GetKey() == 40)
		{
			if(menuState < ITENS_QTT)
			{
				menuState ++;
			}
			else
			{
				menuState = 0;
			}
		}
	}
}
